﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GovernmentOfficeProject.LevelDataAccess;
using GovernmentOfficeProject.LevelDataAccessModel;

namespace GovernmentOfficeProject.LevelBusinessLogic
{
    public class BLL_Department
    {

        public BLL_Department()
        {

        }

        public List<Entity_USER_Department> getDeptList()
        {
            try
            {
                return new DAL_USER_Department().getDeptList();
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        public Entity_USER_Department getDeptByDeptID(decimal deptID)
        {
            try
            {
                return new DAL_USER_Department().getDeptByDeptID(deptID);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        public List<Entity_USER_Department> getDeptByCondition(Entity_USER_Department deptEntity)
        {
            try
            {
                return new DAL_USER_Department().getDeptListByDeptEntity(deptEntity);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        public List<Entity_USER_Department> getDeptListByUser(Entity_USER_User userEntity)
        {
            try
            {
                if (userEntity!=null)
                {
                     return new DAL_USER_Department().getDeptListByUserID(userEntity.UserID);
                }
                return new List<Entity_USER_Department>();
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
        
        public bool addDept(Entity_USER_Department deptEntity)
        {
            try
            {
                return new DAL_USER_Department().addDeptartment(deptEntity);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        public bool updateDeptByDeptIDAndEntity(decimal deptID, Entity_USER_Department deptEntity)
        {
            try
            {
                return new DAL_USER_Department().updateDeptByDeptID(deptID, deptEntity);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        public bool deleteDeptByDeptID(decimal deptID)
        {
            try
            {
                return new DAL_USER_Department().deleteDeptByDeptID(deptID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        //获取部门下的用户数量
        public int getUserCountByDeptID(decimal deptID)
        {
            try
            {
                return new DAL_USER_UserDept().getUserCountByDeptID(deptID);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
    }
}
